/*
 * @Author: wanghan
 * @Date:   2018-04-18 09:54:09
 * @Last Modified by:   wanghan
 * @Last Modified time: 2018-04-18 09:54:11
 */
$(function() {
	//绝对路径地址的获取
	var curWwwPath = window.document.location.href;
	//获取主机地址之后的目录
	var pathName = window.document.location.pathname;
	console.log(curWwwPath)
	console.log(pathName)
	var num = pathName.indexOf("/hys-helpList");
	// var num= pathName.lastIndexOf("/");
	var str = pathName.substr(0, num);
	console.log(str)
	var pos = curWwwPath.indexOf(pathName);
	//获取主机地址
	var localhostPaht = curWwwPath.substring(0, pos);
	console.log(localhostPaht + str);
	var urlStr = localhostPaht + str;
	console.log(urlStr)

	viewlocation()

	$('ul li').on('click', 'div', function(event) {
		event.preventDefault();
		console.log(urlStr)
		// 获取标题名
		var currentTitle = $(this).children('p').text().trim();
		// 获取当前类名
		var currentClass = $(this).attr('class');
		console.log(currentTitle);
		console.log(currentClass);
		var url = urlStr + "/hys-helpList/" + currentClass + ".html";
		if (window.mobileAgent.isRunOnApp()) {
			window.mobileAgent.openNewWindow(url, currentTitle);
		} else {
			//console.log(urlyes);
			window.open(url);
		}
	});

	function viewlocation() {
		if(window.mobileAgent.isRunOnApp()) {
			var left = document.getElementById("manager").getBoundingClientRect().left;
			var top = document.getElementById("manager").getBoundingClientRect().top;
			var width = document.getElementById("manager").getBoundingClientRect().width;
			var height = document.getElementById("manager").getBoundingClientRect().height;
			console.log("js中获取屏幕宽度::"+window.screen.width);
			console.log("js中获取屏幕高度::"+window.screen.height);
			console.log("js中获取left::"+left);
			console.log("js中获取top::"+top);

			var viewMargin = {
				left: left / window.screen.width,
				top: top / window.screen.height,
				width: width / window.screen.width,
				height: height / window.screen.height
			} //margin可不传

			window.window.mobileAgent.viewlocation(function(err, rs) {
				if(rs != null) {
					var url = urlStr + "/hys-helpList/manager.html";
					if (window.mobileAgent.isRunOnApp()) {
						window.mobileAgent.openNewWindow(url, "车辆管理");
					} else {
						//console.log(urlyes);
						window.open(url);
					}
				}
			}, viewMargin);
		}
	}
})
